package cn.paidaxin.task;

import cn.paidaxin.constants.SytemConstants;
import cn.paidaxin.domain.dto.ClockInDTO;
import cn.paidaxin.domain.properties.XinnuoMsgProperties;
import cn.paidaxin.service.ClockinCoreOpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * 注: 谷歌驱动下载地址:http://npm.taobao.org/mirrors/chromedriver/
 * 驱动版本一定要与浏览器一致!!!!!
 * ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
 * 查看浏览器版本只能用输入url的方式查看 :chrome://version/
 * 其他方式可能会导致浏览器自动升级,最新版本的浏览器可能没有对应的驱动
 *
 * @author Pai dx
 * @Description 打卡任务
 * @date 2021-08-20 11:27
 **/
@Configuration
@EnableScheduling
@Slf4j
public class SeleniumTask {

    @Autowired
    private ClockinCoreOpService clockinCoreOpService;

    @Autowired
    private XinnuoMsgProperties xinnuoMsg;

    /**
     * 上班卡 周一到周五的 8点21
     */
    @Scheduled(cron = "0 21 8 ? * 1,2,3,4,5")
//    @Scheduled(cron = "0 21 8 ? * 1,2,3,4")
    public void zsxnAutoLoginTask() throws Exception {
        ClockInDTO clock = new ClockInDTO();
        clock.setClockType(SytemConstants.BE_ON_DUTY_TAG);
        clock.setPassword(xinnuoMsg.getPassword());
        clock.setUsername(xinnuoMsg.getUsername());
        clock.setPhone(xinnuoMsg.getSmsSendPhone());
        boolean flag = clockinCoreOpService.clockinCoreOp(clock);
        log.info("打卡状态: {}",flag);

    }

    /**
     * 下班卡 周一到周五的 18点
     */
    @Scheduled(cron = "0 0 18 ? * 1,2,3,4,5")
//    @Scheduled(cron = "0 0 18 ? * 1,2,3,4")
    public void zsxnAutoEndTask() throws Exception {
        ClockInDTO clock = new ClockInDTO();
        clock.setClockType(SytemConstants.GET_OFF_WORK_TAG);
        clock.setPassword(xinnuoMsg.getPassword());
        clock.setUsername(xinnuoMsg.getUsername());
        clock.setPhone(xinnuoMsg.getSmsSendPhone());
        boolean flag = clockinCoreOpService.clockinCoreOp(clock);
        log.info("打卡状态: {}",flag);
    }
}
